package com.zwj.spring_study.a05;

import lombok.extern.slf4j.Slf4j;
import org.mybatis.spring.mapper.MapperScannerConfigurer;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.BeanDefinitionCustomizer;
import org.springframework.context.annotation.ConfigurationClassPostProcessor;
import org.springframework.context.support.GenericApplicationContext;

import java.util.Arrays;

/**
 * @author 张文接
 * @version 1.0
 * @createTime 2024/6/2 22:40
 */
@Slf4j
public class A05Application {
    public static void main(String[] args) {
        GenericApplicationContext context = new GenericApplicationContext();
        //注册Bean  Config
        context.registerBean(Config.class);
        //注册BeanFactoryPostProcessor 拓展@Configuration @Bean @ComponentScan 等注解的解析
        context.registerBean(ConfigurationClassPostProcessor.class);
        //添加解析@Mapper注解的后置处理器
        context.registerBean(MapperScannerConfigurer.class, new BeanDefinitionCustomizer() {
            @Override
            public void customize(BeanDefinition beanDefinition) {
                beanDefinition.getPropertyValues().add("basePackage","com.zwj.spring_study.a05.mapper");
            }
        });
        //容器初始化
        context.refresh();
        Object bean = context.getBean("mapper1");
        //打印容器中的Bean
        Arrays.stream(context.getBeanDefinitionNames()).forEach(System.out::println);


    }
}
